<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>


        let users = [
            ['zhangsan', '123', 100],
            ['lisi', '000', 1000],
            ['lihua', '567', 0],
        ]

        start();

        function start() {
            const option = prompt('请选择操作：1.登录  2.注册');
            if (option == 1) {
                login();
            } else if (option == 2) {
                register();
            }
        }


        function register() {
            const account = prompt('请输入注册账号：')
            // 判断账号是否存在
            for (let item of users) {
                if (item[0] == account) {
                    alert('该账号已存在，请重新输入。');
                    register();
                    return;
                }
            }

            // 当for循环执行完成，都没有提示账号存在，说明当前账号可用
            const password = prompt('请输入注册密码');
            users.push([account, password, 0])
            alert('注册成功！');
            login();
        }



        function login() {
            const account = prompt('请输入登录账号');
            const password = prompt('请输入登录密码');

            for (let item of users) {
                if (item[0] == account && item[1] == password) {
                    alert('登录成功');
                    return;
                }
            }

            alert('登录失败')
        }

    </script>
</body>

</html>